package edu.upc.clase.demo.controller;

import edu.upc.clase.demo.entity.Participante;
import edu.upc.clase.demo.entity.Torneo;
import edu.upc.clase.demo.service.ParticipanteService;
import edu.upc.clase.demo.service.TorneoService;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.support.SessionStatus;
import org.springframework.web.servlet.ModelAndView;

/**
 *
 * @author gian
 */
@Controller("participanteController")
public class ParticipanteController {

    @Autowired
    private ParticipanteService participanteService;
    private static Logger log = LoggerFactory.getLogger(ParticipanteController.class);

    @Autowired
    private TorneoService torneoService;
    
    @RequestMapping(value = "/participante/new", method = RequestMethod.GET)
    public ModelAndView newParticipante() {
        ModelAndView mav = new ModelAndView("participante/new");
        Participante participante = new Participante();
        mav.getModelMap().put("participante", participante);
        return mav;
    }

    @RequestMapping(value = "/participante/new", method = RequestMethod.POST)
    public String createParticipante(@ModelAttribute("participante")Participante participante, SessionStatus status) {    
        participanteService.insertar(participante);
        status.setComplete();

        return "redirect:/pages/participante/index";
        
    }
    
    @RequestMapping("/participante/participar")
    public ModelAndView login() {
        ModelAndView mav = new ModelAndView("participante/participar");
        List<Torneo> torneo = torneoService.buscarTodos();
        Participante participante = new Participante();
        mav.getModelMap().put("torneo", torneo);
        mav.getModelMap().put("participante", participante);
        return mav;
    }

    /*@RequestMapping("/participante/index")
    public ModelAndView index() {
        ModelAndView mav = new ModelAndView("participante/index");
        List<Participante> participante = participanteService.buscar(Integer id);
        CriterioBusqueda criterioBusqueda = new CriterioBusqueda();
        mav.addObject("participante", participante);
        mav.addObject("criterioBusqueda",criterioBusqueda);
        return mav;
    }*/
    
}


